/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;
import javax.persistence.*;
import jpapractica.*;

public class SoundtrackManager {
    EntityManagerFactory emf;
    EntityManager managerSoundTrack;
    
    public SoundtrackManager(){
        emf= Persistence.createEntityManagerFactory("GRLUPU");
        managerSoundTrack= emf.createEntityManager();
    }
    
    public Soundtrack create (int id, String picture){
        
        Soundtrack bandaSonora = new Soundtrack(id, picture);
        managerSoundTrack.getTransaction().begin();
        managerSoundTrack.persist(bandaSonora);
        managerSoundTrack.getTransaction().commit();
        return bandaSonora;
    }
    public void delete(int id){
        Soundtrack bandaSonora = managerSoundTrack.find(Soundtrack.class, id);
        managerSoundTrack.getTransaction().begin();
        managerSoundTrack.remove(bandaSonora);
        managerSoundTrack.getTransaction().commit();
        
        
    }
    public void update(int id, String picture){
        Soundtrack bandaSonora = managerSoundTrack.find(Soundtrack.class, id);
        managerSoundTrack.getTransaction().begin();
        bandaSonora.setPicture(picture);
        managerSoundTrack.getTransaction().commit();
        
        
    }    
    
}
